package com.itcast.cn.jsp.controller;

import com.itcast.cn.jsp.pojo.Brand;
import com.itcast.cn.jsp.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author hyatt
 */
@WebServlet("/updateServlet")
public class UpdateBrandServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        // 获取参数
        String brandName = request.getParameter("brandName");
        String companyName = request.getParameter("companyName");
        String ordered = request.getParameter("ordered");
        String description = request.getParameter("description");
        String status = request.getParameter("status");
        String id = request.getParameter("id");
        System.out.println("id: " + id);
        // 调用service的插入方法
        // 创建一个对象
        Brand brand = new Brand(Integer.valueOf(id), brandName, companyName, Integer.valueOf(ordered), description, Integer.valueOf(status));
        new BrandService().update(brand);
        // 跳转到查询界面，看是否成功
        request.getRequestDispatcher("/selectAll").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
